package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealDishMapper {
    /**
     * 根据菜品id查询对应的套餐id
     *
     * @param dishIds 菜品id
     * @return 套餐id
     */
    List<Long> getSetMealIdsByDishIds(List<Long> dishIds);

    /**
     * 批量添加套餐菜品关联数据
     *
     * @param setmealDishes 套餐菜品数据
     */
    void insertBatch(List<SetmealDish> setmealDishes);

    /**
     * 根据套餐id删除关联数据
     *
     * @param setmealId 套餐id
     */
    @Delete("DELETE FROM setmeal_dish WHERE setmeal_id = #{setmealId}")
    void deleteBySetmealId(Long setmealId);

    /**
     * 根据套餐id集合删除关联数据
     *
     * @param setmealIds 套餐id集合
     */
    void deleteBySetmealIds(List<Long> setmealIds);

    /**
     * 根据套餐id查询关联数据
     *
     * @param setmealId 套餐id
     * @return 关联数据
     */
    @Select("SELECT * FROM setmeal_dish WHERE setmeal_id = #{setmealId}")
    List<SetmealDish> getBySetMealId(Long setmealId);

    /**
     * 根据套餐id查询菜品选项
     *
     * @param setmealId 套餐id
     * @return 查询结果
     */
    @Select("SELECT sd.name, sd.copies, d.image, d.description " +
            "FROM setmeal_dish sd LEFT JOIN dish d ON sd.dish_id = d.id " +
            "WHERE sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
